﻿using System;
using Core.AbstractEntities;

namespace Operations.Entities
{
    /// <summary>
    /// Execute operation for each item added in the stack
    /// </summary>
    public class OperationRPL : Operation
    {
        /// <summary>
        /// Constructor by default
        /// </summary>
        public OperationRPL(HpCollection hpCollection)
        {
            this.HpCollection = hpCollection;
        }
        /// <summary>
        /// Execute operation for each item added in the stack
        /// </summary>
        public override HpElement Execute()
        {
            HpElement element1 = HpCollection.Get(HpCollection.Count - 1);
            string command = element1.Value.ToString().Replace("«", "").Replace("»", "").Trim();
            if (command.Equals("DUP"))
                return HpCollection.Get(HpCollection.Count - 2);
            else
                throw new NotImplementedException("RPL command not implemented");
        }
    }
}
